new Vue({
    el: '#detail',
    data:{
        //场地列表
        placelist:[],
        //场地信息
        places:[],
        //分页展示
        page:"",
        //场地楼层
        placestorey:"",
        //场地类型
        placetype:"",
        //场地编号
        place_no:"",
        //错误信息
        message:"",
        //展示
        show : "",
        //审核不通过列表
        disables:[]
    },
    methods:{
        checkPlaceNo:function (e){
            var a;
            $.ajax({
                // 设置json的属性和值
                url: "/checkPlaceNo",
                contentType: "application/json;charset=UTF-8",
                data: {'placeno':this.place_no},
                async:false,
                type: "get",
                success: function (data) {
                    if(data) {
                        a = "该场地编号已存在"
                        e.preventDefault()
                    }else {
                        a = ""
                        return true
                    }
                }
            })
            this.message = a;
        },
        //获取场地信息
        getPlaces(pageNum){
            var placelist;
            var pages;
            $.ajax({
                // 设置json的属性和值
                url: "/getPlaces",
                contentType: "application/json;charset=UTF-8",
                data: {'pageNum':pageNum},
                async:false,
                type: "get",
                success: function (data) {
                    placelist = data.placeList
                    pages = data.pages
                }
            })
            this.places = placelist
            this.page = pages
            this.show = '11'
        },
        //获取审核未通过列表
        getDisables(){
            var diasables;
            $.ajax({
                // 设置json的属性和值
                url: "/getPlaces",
                contentType: "application/json;charset=UTF-8",
                data: {'pageNum':pageNum},
                async:false,
                type: "get",
                success: function (data) {
                    diasables = data
                }
            })
            this.disables = diasables
        },
        //删除场地
        deletePlace(index){
            $.ajax({
                // 设置json的属性和值
                url: "/deletePlace",
                contentType: "application/json;charset=UTF-8",
                data: {'placeno':this.places[index].place_no},
                async:false,
                type: "get",
                success: function (data) {
                    if(data===1){
                        alert("删除成功")
                    }
                }
            })
            this.places.splice(index,1);
        },
        //搜索场地信息--分页查询
        researchPlaces(pageNum){
            var placelist;
            var pages;
            $.ajax({
                // 设置json的属性和值
                url: "/searchPlace",
                contentType: "application/json;charset=UTF-8",
                data: {'pageNum':pageNum,
                       'placestorey':this.placestorey,
                       'placetype':this.placetype
                },
                async:false,
                type: "get",
                success: function (data) {
                    placelist = data.placeList
                    pages = data.pages
                }
            })
            this.places = placelist
            this.page = pages

            this.show = '22'
        }
    },
    created(){
        this.getPlaces(1)
        this.getDisables()
    }
});